package org.jimm.app.util;

import java.util.Vector;

import org.jimm.app.R;

import android.content.Context;

public class Func {
	private static Context mContext;
	
	public static final String LOG_TAG = "Jimm:Func";

	/*
	 * String[] a = source.split(", "); 
	 */
		public static String[] explode(String text, char separator)
	{
		Vector tmp = new Vector();
		StringBuffer strBuf = new StringBuffer();
		int len = text.length();
		char chr;
		for (int i = 0; i < len; i++)
		{
			chr = text.charAt(i);
			if (chr == separator)
			{
				tmp.addElement(strBuf.toString());
				strBuf.delete(0, strBuf.length());
			} else
				strBuf.append(chr);
		}
		tmp.addElement(strBuf.toString());
		String[] result = new String[tmp.size()];
		tmp.copyInto(result);
		return result;
	}
		

	/**
     * The function checks whether the string in an array
     * @param text String for search in array.
     * @param arr array.
     * @return true if the string in the array
     */
		public static boolean CheckMass (String text, String[] arr)
		{
			boolean res=false;
			int strLenght=arr.length;
	        for (int i=0;i<strLenght;i++){
	        	if (text.equals(arr[i])){
	                res=true;
	                break;
	            }}
	        return res;
	        }

		public static String WordEnd(int col,Context context) {
			// For the great and mighty Russian language. =) 
	      String lang = context.getResources().getConfiguration().locale.getLanguage();
	      String wordend;
	      if ("ru".equals(lang)) {
	    	  int cols = col;
	     wordend = String.valueOf(cols);
	     int colend = Integer.parseInt(wordend);
	     int numbers = colend%10;
	     switch (numbers) {
	     case 1:  wordend = context.getText(R.string.MessOne).toString();  break;
	     case 2:  wordend = context.getText(R.string.MessSeveral).toString();  break;
	     case 3:  wordend = context.getText(R.string.MessSeveral).toString();  break;
	     case 4:  wordend = context.getText(R.string.MessSeveral).toString();  break;
	     case 5:  wordend = context.getText(R.string.MessMany).toString();  break;
	     case 6:  wordend = context.getText(R.string.MessMany).toString();  break;
	     case 7:  wordend = context.getText(R.string.MessMany).toString();  break;
	     case 8:  wordend = context.getText(R.string.MessMany).toString();  break;
	     case 9:  wordend = context.getText(R.string.MessMany).toString();  break;
	     case 0:  wordend = context.getText(R.string.MessMany).toString();  break;
	     default: wordend = context.getText(R.string.MessMany).toString();  break;
	  }
	     if (colend<15 & colend>10) {wordend = context.getText(R.string.MessMany).toString();}
	     
	      } 
	     //for another lang
	      else {
	     if (col==1) {
	  	   wordend = context.getText(R.string.MessOne).toString();
	  	   } else 
	  	   {
	  		 wordend = context.getText(R.string.MessMany).toString();
	  		}           
	      }
		return wordend;
		}
	}
